<?php

	  // session_start();
	  // $uid=session('uid');
	  // if(!empty($uid)&&isset($uid)){
	  //    $logininfor='<a href="__GROUP__/Uc/index.html" class="loginname">'.$_SESSION['loginname'].'</a>&nbsp;&nbsp;<a href="#" class="outlogin">[退出]</a>';
	  // } else{
	  //     $logininfor='<a href="'.U("home/Index/login").'" style=" color:#B61D1D;">&nbsp;您s好，&nbsp;&nbsp;请登录</a>&nbsp;&nbsp;<a href="__APP__/index/reg.html">免费注册</a>';
	  // }
   //   define('__LOGINFOR__',$logininfor);
	 define('__SYSTEMNAME__','霞客');
	 $cartshop=cookie('cartshop');
	 $cartshop_num=count($cartshop);
	 define('__CARTSHOPNUM__',$cartshop_num);
     
     //根据用户id获取用户名称的方法
	 function getUserName($uid=''){
          if($uid=='') $uid=session('uid');
          $username=M('User')
                   ->where(array('user_id'=>$uid))
                   ->getField('user_name');
           return $username;
	 }
	 //根据相册字符串获取相册封面的方法
	 function getalbumface($string){
          $pic=explode(',',$string);
           if($pic[0]){
                return __ROOT__.$pic[0];
           }elseif($pic[1]){
                return __ROOT__.$pic[1];
           }else{
                 return __ROOT__.'/Public/home/images/no_img.jpg';
           }
	 }
	 //获取当前登录会员的信息
	 function getUserInfo(){
	 	$uid=is_login();
	 	$user=M('User')
            ->alias('a')
            ->where('a.user_id='.$uid)
            ->JOIN("LEFT JOIN __USER_INFO__ b ON a.user_id = b.user_id")
            ->find();
        return $user;
	 }
	 //获取商品的详情
	 function getGoodInfo($id){
         $goodinfo=M('Goods')->where(array('go_id'=>$id))->find();
         return $goodinfo;
	 }
	 //获取购物车订单总额
	 function getShop(){
       session_start();
       if($_SESSION['shop']){
           $order_good=$_SESSION['shop'];
           $total=0;
          foreach ($order_good as  &$value) {
             $value['go_info']=getGoodInfo($value['id']);
             $total=$total+$value['go_info']['go_value']*$value['number'];
          }
          $return=array(
          	'order_good'=>$order_good,
          	'total'=>$total
          	);
          return $return;
       }else{
             $this->error("您订单里无商品",U('Index/index'));         
       }
	 }
   //获取支付方式
   function getPayName($id){
       $payName=M('PayWay')
               ->where(array('payway_id'=>$id))
               ->getField('payway_name');
       return $payName;
   }
   //获取支付方式
   function getSendName($id){
       $sendName=M('SendWay')
               ->where(array('sendway_id'=>$id))
               ->getField('sendway_name');
       return $sendName;
   }
   //获取地址名称
   function getAdName($id){
        $name=M('Address')
             ->where(array('addr_id'=>$id))
             ->getField('addr_name');
        return $name;
   }
   //获取商品名称
   function getgoName($go_id){
        $go_name=M('Goods')
                ->where(array('go_id'=>$go_id))
                ->getField('go_name');
        return $go_name;
   }
   //根据索引获取收货地址的json
   function getJsonAddress($index){
        $uid=session('uid');
        $addreess=M('UserInfo')
                 ->where(array('user_id'=>$uid))
                 ->getField('ui_address');
        $addreess=json_decode($addreess,true);
        return $addreess[$index];
   }

   function shiyan(){
       return '5';
   }

?>